package com.cy.store.config;

import com.cy.store.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;
@Configuration
public class LoginInterceptorConfigurer implements WebMvcConfigurer {
    HandlerInterceptor interceptor = new LoginInterceptor();

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> patterens  =new ArrayList<>();
        patterens.add("/bootstra3/**");
        patterens.add("/css/**");
        patterens.add("/images/**");
        patterens.add("/js/**");
        patterens.add("/web/login.html");
        patterens.add("/web/register.html");
        patterens.add("/web/index.html");
        patterens.add("/web/product.html");
        patterens.add("/users/reg");
        patterens.add("/users/login");
        //addPathPatterns需要拦截的内容
        registry.addInterceptor(interceptor).addPathPatterns("/**").excludePathPatterns(patterens);
    }
}
